//
//  MMWSmartLibrary.h
//  smartLibraryTest
//
//  Created by gaogao on 15/12/5.
//  Copyright (c) 2015year miotlink. All rights reserved.
//

#import <Foundation/Foundation.h>



@interface MMWMiotLinkDeviceInfo : NSObject

@property(nonatomic, strong)NSString *ip;
@property(nonatomic, strong)NSString *mac;
@property(nonatomic, assign)uint16_t port;

@end


@interface MMWMiotLinkResultDeviceInfo : NSObject

@property(nonatomic, assign)int resultCode;
@property(nonatomic, strong)NSString *ip;
@property(nonatomic, strong)NSString *kind;
@property(nonatomic, strong)NSString *mac;
@property(nonatomic, strong)NSString *ver;
@property(nonatomic, strong)NSString *model;


@end


/**
 * mmw_MiotLinkConfig The result block of the interface.
 *
 * @param deviceDic Device information, 1 success, -1 failure.
 */
typedef void(^mmw_MiotLinkConfigBlock)(NSDictionary *deviceDic);

/**
 * mmw_MiotLinkFirstConfig The result block of the interface.
 *
 * @param resultDic Device information, 1 success, -1 failure.
 */
typedef void(^ mmw_MiotLinkFirstConfigBlock) (NSDictionary *resultDic);

/**
 * mmw_MiotLinkFirstConfig The result block of the interface.
 *
 * @param resultCode Device information, 1 success, -1 failure.
 */
typedef void(^ mmw_MiotLinkFirstConfigPlatformBlock) (int resultCode);


/**
 * mmw_MiotLinkGetAllMacAndIP The result block of the interface.
 *
 * @param allMacAndIP All devices Mac and Ip information failed to be empty.
 */
typedef void(^ mmw_MiotLinkGetAllMacAndIP) (NSArray *allMacAndIP);



/**
 * mmw_MiotLinkGetIP The result block of the interface.
 *
 * @param device All devices Mac and Ip information failed to be empty.
 */
typedef void(^ mmw_MiotLinkGetIPBlock) (MMWMiotLinkDeviceInfo *device);


@interface MMWMiotLink : NSObject

/**
 *  Whether the connection platform is formal.
 *  The default is the formal server, Yes is the formal server, and No is the test server.
 */
@property(nonatomic,assign)BOOL isOfficialServer;

/**
 *  Get a singleton from the MMWSmartLibrary.
 *
 *  @return Return to the MMWSmartLibrary singleton.
 */
+ (instancetype)shareInstence;

/**
 * Configure the connection router.
 *
 * @param routeSSid Router hotspot name
 * @param password  Router password
 *
 * @param configMode Configuration mode
 *          1 For the old version of smartConfig
 *          2 For smartConnect (7681).
 *          3 Configuration of hanfeng
 *          4 for the new version of smartConfig and lexin configuration.
 *
 * @param time      Timeout: 60 seconds minimum
 * @param callBack  Results the callback
 *
 */
- (void)mmw_MiotLinkConfig:(NSString *)routeSSid
                  password:(NSString *)password
                configMode:(int)configMode
                      time:(int)time
                  callBack:(mmw_MiotLinkConfigBlock)callBack;

/**
 * Ap configuration
 *
 * @param routeSSid Router hotspot name
 * @param password  Router password
 *
 *
 * @param time      Timeout: 60 seconds minimum.
 * @param callBack  Results the callback
 *
 */
- (void)mmw_apMiotLinkConfig:(NSString *)routeSSid
                  password:(NSString *)password
                      time:(int)time
                  callBack:(mmw_MiotLinkConfigBlock)callBack;



/**
 * Hanfeng and lexin configuration equipment information.
 *
 * @param device Equipment related information
 *
 * @param serial    Serial port configuration information, no serial port information for null.
 * @param time      Timeout period, minimum 40 seconds.
 * @param callBack  Results the callback
 *
 */
- (void)mmw_HFMiotLinkFirstConfig:(MMWMiotLinkDeviceInfo *)device
                         serial:(NSString *)serial
                           time:(int)time
                       callBack:(mmw_MiotLinkFirstConfigBlock)callBack;


/**
 * Configure device information
 *
 * @param device Equipment related information
 *
 * @param userPlatformMode User platform configuration mode.
 *          0：No user platform information is configured.
 *          1：The device is the TCP server side.
 *             Parameter userPlatformPort cannot be empty.
 *          2：The device connects to the client server by TCP.
 *             Parameter userPlatformURL, userPlatformPort cannot be empty.
 *          4：The device connects to the client server in UDP mode.
 *             Parameter userPlatformURL, userPlatformPort cannot be empty.
 *
 * @param userPlatformURL   User platform URL, 2,4 mode cannot be empty.
 * @param userPlatformPort  The user platform port cannot be empty.
 * @param serial            Serial port configuration information, no serial port information for null.
 * @param time              Timeout period, minimum 40 seconds.
 * @param callBack          Results the callback
 *
 */
- (void)mmw_MiotLinkFirstConfig:(MMWMiotLinkDeviceInfo *)device
               userPlatformMode:(int)userPlatformMode
                userPlatformURL:(NSString *)userPlatformURL
               userPlatformPort:(NSString *)userPlatformPort
                         serial:(NSString *)serial
                           time:(int)time
                       callBack:(mmw_MiotLinkFirstConfigPlatformBlock)callBack;




/**
 * Get MAC addresses and IP addresses for all devices.
 *
 * @param SearchTime    Search time
 * @param callBack      Results the callback
 */
- (void)mmw_MiotLinkGetAllMacAndIPSearchTime:(int)SearchTime
                                    callBack:(mmw_MiotLinkGetAllMacAndIP)callBack;


/**
 *  Stop configuration (including access to device IP)
 */
- (void)mmw_MiotLinkStopLink;

/**
 *  Data encoding
 * @param command The command sent to the device.
 */
+ (NSData *)encodeDataWithCommand:(NSString *)command;

/**
 *  The data decoding
 * @param data Data that needs to be decoded.
 */
+ (NSDictionary *)decodeDeviceData:(NSData *)data;

@end
